<template>
	<view class="all">
		<view class="status_bar">
			<!-- 这里是状态栏 -->
		</view>
		<view class="fidexs">
			<view class="all_title">
				<view class="groups" @click="tos">
					<u-icon name="arrow-left" :bold="true" color="rgba(46, 46, 46, .5)" size="20"></u-icon>
				</view>
				<u-icon name="setting" color="rgba(46, 46, 46, .5)" @click="mesg" size="28"></u-icon>
			</view>
		</view>
		<view class="content_l">
			<view class="nav">
				{{list.chapterTitle}}
			</view>
			<u--text size="38rpx" lineHeight="74rpx" color="rgb(46, 46, 46)" :text="list.content"></u--text>
			<u-line color="#8c8c8c" margin="50rpx 0 50rpx"></u-line>
			<view class="but">
				<u-button :plain="true" :hairline="true" type="primary" text="上一章"
					@click="prev(list.prevChapterId,list.sourceId)"></u-button>
				<u-button @click="nav(list.sourceId,chapterSort)" :plain="true" :hairline="true" type="primary"
					text="目录"></u-button>
				<u-button :plain="true" :hairline="true" type="primary" text="下一章"
					@click="next(list.nextChapterId,list.sourceId)"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: '',
				page: '',
				chapterSort: ''
			}
		},
		methods: {
			tos() {
				uni.navigateBack({
					delta: 1
				})
			},
			prev(a, i) {
				if (a == undefined) {
					uni.navigateTo({
						url: '/pages/write/write?chapterId=' + '' + '&sourceId=' + i
					})
				} else {
					uni.navigateTo({
						url: '/pages/write/write?chapterId=' + a + '&sourceId=' + i
					})
				}

			},
			next(a, i) {
				console.log(a, i, 2132132)
				if (a == undefined) {
					uni.navigateTo({
						url: '/pages/write/write?chapterId=' + '' + '&sourceId=' + i
					})
				} else {
					uni.navigateTo({
						url: '/pages/write/write?chapterId=' + a + '&sourceId=' + i
					})
				}
			},
			nav(i, a) {
				console.log(i, a, 10000000)
				uni.navigateTo({
					url: '/pages/layout/layout?sourceId=' + i + '&page=' + a
				})
			}
			// mesg() {
			// 	uni.navigateTo({
			// 		url: '/pages/message/message'
			// 	})
			// },
		},
		onLoad(option) {
			console.log(option, 99999999999999)
			this.page = option.page
			
			uni.$http.get('https://m.taoyuewenhua.com/ajax/chapter_content?sourceName=tf&sourceId=' + option.sourceId +
					'&chapterId=' + option.chapterId
					).then(res => {
					this.list = res.data.data
					console.log(this.list,55555)
					this.chapterSort = Math.ceil((res.data.data.chapterSort - 99) / 100)
					uni.setStorage({
						key: 'sign',
						data: this.list.sourceId,
						success: function() {
							console.log('success');
						}
					});
					// 页数
					uni.setStorage({
						key: 'sign' + option.sourceId,
						data: this.list.chapterId,
						success: function() {
							console.log('缓存页数成功');
						}
					});
				}).catch(err => {
				console.log(err)
			})
		}
	}
</script>

<style lang="scss">
	.status_bar {
		height: var(--status-bar-height);
		background-color: #fff;
		width: 100%;
	}

	.all {
		background: #eee;
		width: 100%;
	}

	.fidexs {
		position: fixed;
		top: var(--status-bar-height);
		right: 0;
		left: 0;
		background: #fff;
		z-index: 11;
		border-bottom: 2rpx solid #eee;
	}

	.all_title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 30rpx;
		height: 80rpx;
		border-bottom: 2rpx solid #ededed;
		background-color: #fff;

		.groups {
			display: flex;
			align-items: flex-end;

			.mod {
				margin-left: 20rpx;
			}
		}
	}

	.content_l {
		padding: 140rpx 30rpx 0;

		background-color: #edd9bd;

		.nav {
			text-align: center;
			color: rgb(46, 46, 46);
			font-size: 54rpx;
			padding-bottom: 60rpx;
		}

		.but {
			display: flex;
		}
	}
</style>
